package com.epsoft.odin7cj.flow.api.deploy;

import java.util.ArrayList;
import java.util.List;

//import org.activiti.engine.RepositoryService;
//import org.activiti.engine.repository.Deployment;

import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.repository.Deployment;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.epsoft.odin7cj.core.dto.RetData;
import com.epsoft.odin7cj.flow.model.deploy.FlowDeployment;
import com.epsoft.odin7cj.flow.util.BpmnBeanUtils;

/**
 * DESC: 流程模板 <br>
 * @author 胡义振
 * @date 2020年5月20日
 */
@RestController
@RequestMapping("/api/flow/deploy")
public class DeploymentApi {

	@Autowired
	private RepositoryService repositoryService;
	
	/**
	 * DESC: 流程发布
	 * @param deployName 流程的名称 
	 * @param bpmnPath 资源文件的 bpmn 目录中的资源（不含后缀）
	 * @return
	 */
	@RequestMapping("/getList")
	public RetData<List<FlowDeployment>> deployBpmnConfig(String tmplId) {
		RetData<List<FlowDeployment>> retData = new RetData<List<FlowDeployment>>();
		List<FlowDeployment> flowDeploymentList = new ArrayList<FlowDeployment>();
		List<Deployment> listDeployment = repositoryService.createDeploymentQuery().list();
		for(Deployment deployment: listDeployment) {
			flowDeploymentList.add(BpmnBeanUtils.convertToFlowDeployment(deployment));
		}
		retData.setRetBody(flowDeploymentList);
		return retData;
	}
	
    /**
     * DESC: 删除流程发布
     * @param deploymentId  流程发布ID
     * @return
     * @throws Exception
     */
	@RequestMapping("/doDelDeployment")
    public RetData<String> doDelDeployment(String deploymentId) throws Exception {
		RetData<String> retData = new RetData<String>();
		repositoryService.deleteDeployment(deploymentId, true);
    	retData.setRetBody("");
    	return retData;
    }
	
}
